package cn.itqiqi.student_system_java.utils;

import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description
 * @date 2022-06-18 23:52
 */
@Component
public class ResultUtils {

    private final TreeMap<String, Object> jsonMap = new TreeMap<>();

    public String success (Object data) {
        return success(data, "获取成功!");
    }

    public String success (int code, Object data, String msg) {
        return result(code, data, msg);
    }

    public String success (Object data, String msg) {
        return result(200, data, msg);
    }

    public String success (String msg) {
        return result(200, null, msg);
    }

    public String fail (int code, String msg) {
        return result(code, null, msg);
    }

    public String result (int code, Object data, String msg) {
        jsonMap.clear();
        jsonMap.put("code", code);
        jsonMap.put("data", data);
        jsonMap.put("msg", msg);
        return JSONUtil.toJsonStr(jsonMap);
    }

}
